package com.dant.effects
{
	import com.dant.events.AdvancedPanelEvent;
	
	import flash.events.Event;
	
	import mx.effects.EffectManager;
	import mx.effects.effectClasses.TweenEffectInstance;
	import mx.core.mx_internal;

	use namespace mx_internal;

	public class CloseAdvancedPanelInstance extends TweenEffectInstance
	{
		public var alphaFrom:Number;
		
		public var alphaTo:Number;

		public function CloseAdvancedPanelInstance(target:Object)
		{
			super(target);
		}
		
		override public function initEffect(event:Event):void
		{
			super.initEffect(event);
			if (event is AdvancedPanelEvent)
			{
				if (isNaN(alphaFrom))
				{
					alphaFrom = 1;
				}
				if (isNaN(alphaTo))
				{
					alphaTo = 0;
				}
			}
		}

		override public function play():void
		{
			super.play();
			
			// Create a tween to resize and move the object
 			tween = createTween(this, [ alphaFrom ],
											 [ alphaTo ], duration);
											 
			applyTweenStartValues();
 		}

		override public function onTweenUpdate(value:Object):void
		{
			super.onTweenUpdate(value);
 			
			EffectManager.suspendEventHandling();
			
			target.alpha = value[0];
			
			EffectManager.resumeEventHandling(); 
		}

	}
}